package com.attedu.jdbc.homework;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.util.Scanner;

/**
 * @author tune_the last
 * @date 2025/11/3 - 19:32
 */
public class Homework2 {
    public static void main(String[] args) throws Exception{
        Class.forName("com.mysql.cj.jdbc.Driver");
        Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/tedu?characterEncoding=utf8", "root", "ASD13579asd");
        String sql = "UPDATE user SET password = ? WHERE username = ?";
        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        Scanner in = new Scanner(System.in);
        System.out.print("请输入用户名：");
        preparedStatement.setString(2, in.nextLine());
        System.out.print("请输入新密码：");
        preparedStatement.setString(1, in.nextLine());
        int i = preparedStatement.executeUpdate();
        if (i > 0) {
            System.out.println("修改成功");
        }else{
            System.out.println("修改失败");
        }

        connection.close();
    }
}
